package com.tjmc.company.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjmc.company.mapper.DeliveryRecordsMapper;
import com.tjmc.company.service.DeliveryRecordsService;
import com.tjmc.recruit.user.dto.ResumeSearchDTO;
import com.tjmc.company.api.entity.DeliveryRecordsEntity;
import com.tjmc.recruit.user.vo.ResumeInfoVO;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 投递记录表
 *
 * @author recruit
 * @date 2024-11-14 16:56:22
 */
@Service
public class DeliveryRecordsServiceImpl extends ServiceImpl<DeliveryRecordsMapper, DeliveryRecordsEntity> implements DeliveryRecordsService {

    @Override
    public Page<ResumeInfoVO> getResumeDeliveryPage(Page page, ResumeSearchDTO resumeSearchDTO) {
        // 1. 组合查询条件
        Map<String, Object> map = buildResumeSearchParams(resumeSearchDTO);
        // 2. 构造分页条件
        Page<ResumeInfoVO> voPage = new Page<>(page.getCurrent(), page.getSize());
        return baseMapper.getDeliveryResumePage(voPage, map);
    }

    private Map<String, Object> buildResumeSearchParams(ResumeSearchDTO searchDTO){
        Map<String, Object> params = new HashMap<>();
        //用户简历姓名
        if (StrUtil.isNotBlank(searchDTO.getName())) {
            params.put("name", searchDTO.getName());
        }
        if (StrUtil.isNotBlank(searchDTO.getDeliveryRecordsStatus())){
            params.put("deliveryRecordsStatus", searchDTO.getDeliveryRecordsStatus());
        }
        //岗位
        if (StrUtil.isNotBlank(searchDTO.getJobName())) {
            params.put("jobName", searchDTO.getJobName());
        }
        //投递职位名称
        if (StrUtil.isNotBlank(searchDTO.getPublishJobName())) {
            params.put("publishJobName", searchDTO.getPublishJobName());
        }
        //工作经验
        if (StrUtil.isNotBlank(searchDTO.getWorkExperience())) {
            params.put("workExperience", searchDTO.getWorkExperience());
        }
        //年龄开始
        if (ObjectUtil.isNotNull(searchDTO.getAgeStart()) && searchDTO.getAgeStart() > 0) {
            params.put("ageStart", searchDTO.getAgeStart());
        }
        //年龄结束
        if (ObjectUtil.isNotNull(searchDTO.getAgeEnd()) && searchDTO.getAgeEnd() > 0) {
            params.put("ageEnd", searchDTO.getAgeEnd());
        }
        //学历
        if (StrUtil.isNotBlank(searchDTO.getDegree())) {
            params.put("degree", searchDTO.getDegree());
        }
        //是否有照片
        if (StrUtil.isNotBlank(searchDTO.getHasPicture())) {
            params.put("hasPicture", searchDTO.getHasPicture());
        }
        //性别
        if (StrUtil.isNotBlank(searchDTO.getGender())) {
            params.put("gender", searchDTO.getGender());
        }
        //当前状态：及时到岗与否
        if (StrUtil.isNotBlank(searchDTO.getCurrentStatus())) {
            params.put("currentStatus", searchDTO.getCurrentStatus());
        }
        //工作性质：兼职、全职
        if (StrUtil.isNotBlank(searchDTO.getJobProperties())) {
            params.put("jobProperties", searchDTO.getJobProperties());
        }
        return params;
    }

}
